package com.example.backend.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author Double Zhou
 * 返回的数据
 */
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
@AllArgsConstructor
public class ResBean {
    private int errcode;
    private String errmsg;
    @JsonProperty(value="data")
    private Object data = null;

    /**
     * 默认构造函数
     */
    public ResBean() {
        this.setReturnNo(ReturnNo.OK);
    }

    /***
     * 仅带有返回参数的构造函数
     * @param returnNo
     */
    public ResBean(ReturnNo returnNo) {
        this.setReturnNo(returnNo);
    }

    /***
     * 带有错误码和返回结果的构造函数
     * @param returnNo
     * @param data
     */
    public ResBean(ReturnNo returnNo, Object data) {
        this.setReturnNo(returnNo);
        this.data = data;
    }

    public ResBean(Object data) {
        this();
        this.data = data;
    }

    public void setReturnNo(ReturnNo returnNo) {
        this.errcode = returnNo.getErrCode();
        this.errmsg = returnNo.getErrMsg();
    }
}
